<%@ Page Language="C#" MasterPageFile="~/LTR/MlyLtrMaster.Master" AutoEventWireup="true"
  CodeBehind="addWoFile.aspx.cs" StylesheetTheme="Skin1" Inherits="MLY.LTR.addWoFile"
  Title='<%$Dict:addWoFile.Title %>' EnableEventValidation="false" %>

<asp:Content ID="title" ContentPlaceHolderID="titleHolder" runat="server">
  <title>
    <asp:Literal ID="Literal21" Text='<%$Dict:Titles.addWoFile%>' runat="server"></asp:Literal>
  </title>

  <script type="text/javascript">
        function triggerFileUpload() {
            document.getElementById("<%= FileUpload1.ClientID %>").click();
        }
        function setHiddenValue() {
            document.getElementById("<%= Hidden1.ClientID %>").value = document.getElementById("<%= FileUpload1.ClientID %>").value;
        }

        function changeTemplate(e) {
            var newVal = $("#" + e.id + " option:selected").val();
            $('#<%= templateIdHidden.ClientID %>').val(newVal)
        }

        function changeFieldToAdd(e) {
        }

        function changeFieldNameToAdd(e) {
            var newIdx = $("#<%= fieldIdxDdl.ClientID %> option:selected").val();
            $('#<%= itemToAddHidden.ClientID %>').val(newIdx);
            var newVal = $("#<%= newFieldDdl.ClientID %> option:selected").text();
            $('#<%= itemToAddNameHidden.ClientID %>').val(newVal);
        }


        function checkChanged(e) {
            if ($('#' + e.id).is(':checked'))
                $("#<%= hasHeadersHidden.ClientID %>").val("true");
            else
                $("#<%= hasHeadersHidden.ClientID %>").val("");
        }
        window.onload = function() {
            $("#data_transfermenuitem").addClass('active');
        }
  </script>

<%--  <style type="text/css">
    .bigBtn
    {
      background-image: url(/Images/browse/Buttun.jpg);
      border: none;
    }
    .bigBtn:hover
    {
      background-image: url(/Images/browse/Buttun_hilight.jpg);
    }
    #wizardDiv
    {
      height: 600px;
    }
  </style>--%>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div id="data_transfer_container" class="SC_FloatRight"  >
    <div style="text-align: center; width: 100%;">
    <asp:Label ID="errMsgLbl" runat="server" Font-Bold="true" ForeColor="Red"></asp:Label>
    <asp:Label ID="successMsgLbl" Text='<%$Dict:clientAddWoFile.successMsg%>' Visible="false"
      runat="server" Font-Bold="true" ForeColor="Green"></asp:Label></div>
  
    <asp:HiddenField runat="server" ID="templateIdHidden" />
    <asp:HiddenField runat="server" ID="hasHeadersHidden" Value="true" />
    <asp:HiddenField runat="server" ID="itemToAddHidden" Value="" />
    <asp:HiddenField runat="server" ID="itemToAddNameHidden" Value="" />
    
    <asp:Wizard runat="server" ID="myWizard" DisplaySideBar="false" NavigationButtonStyle-CssClass="Btn smallBtn">
      <WizardSteps>
        <asp:WizardStep runat="server" StepType="Start">
          
          <div id="data_transfer_toprow_ChooseTemplate">
            <img src="../Images/Icons/upload_img.png" alt="download" class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Upload data
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Choose a template
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            
          </div>
          <div id="data_transfer_inside"  class="SC_Align">
            <div id="data_transfer_download_image" class="SC_FloatLeft"></div>
            <div id="data_transfer_choose_template" class="SC_FloatLeft">
                <span class="SC_BigText">Choose a template</span><br />
                <span class="SC_SmallText">Choose one of the previously prepared templates.</span><br /><br />
                <%--<asp:CheckBox ID="CheckBox1" name="foo" onclick="javascript:checkChanged(this)" runat="server"
                              Checked="true" Enabled="false"/>
                <asp:Label runat="server" ID="FirstRowHeaderLabel" CssClass="regFont" Text='<%$Dict:clientAddWoFile.containsHeaders %>'></asp:Label>--%>
                <asp:Label ID="Label4" CssClass="regFont" runat="server" Text='<%$Dict:clientAddWoFile.chooseTemplate %>'></asp:Label>
                <asp:DropDownList ID="DropDownList1" runat="server" CssClass="filterddl" onchange="changeTemplate(this)"
                 DataTextField="templateName" AppendDataBoundItems="true" DataValueField="idx">
                </asp:DropDownList>
                <br /><br />
                <asp:FileUpload ID="FileUpload1" runat="server"  />
                <asp:RequiredFieldValidator ID="FileRequired" runat="server" ControlToValidate="FileUpload1" Text="please choose a file" ></asp:RequiredFieldValidator>
                <asp:Button CssClass="smallBtn Btn" ID="delTemplateBtn" Text='<%$Dict:clientAddWoFile.delTemplate %>'                 
                  runat="server"/>
                
            </div>
          </div>
          
          
                   
        </asp:WizardStep>
        <asp:WizardStep runat="server" StepType="Step" ID="fileUploadStep" OnActivate="fileUploadStep_Activate">
          <div id="data_transfer_topRow_file_upload" >
            <img src="../Images/Icons/upload_img.png" alt="download" class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Upload data
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Choose a template
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Browse and check
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
          </div>
          <div id="data_transfer_review_template">
            <div id="data_transfer_browse_image" class="SC_FloatLeft"></div>
            <div id="data_transfer_browse_checkFile" class="SC_FloatLeft">
                <span class="SC_BigText">Check your file</span><br />
            </div>
            
                
          </div>
          <div class="clr"></div>
          <div id="data_transfer_review_grid" class="SC_FloatLeft SC_Align">
          
            <span class="SC_BigText">
            <asp:Label ID="Label5" runat="server" Text='<%$Dict:clientAddWoFile.csvFieldReceived %>'></asp:Label>
            :
            <asp:Label runat="server" ID="templateName"></asp:Label></span>
            <br /><br />
            <asp:GridView ID="userCsvReceived" PageSize="20" AllowPaging="false" SkinID="GridViewSkin"
              runat="server">
              <HeaderStyle CssClass="SC_grid_header"  />
              <RowStyle CssClass="SC_grid_cell"  />
              <Columns>
                <asp:TemplateField HeaderText='<%$Dict:clientAddWoFile.FieldReceivedColumnIdx %>'>
                  <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex + 1   %>'></asp:Label>
                  </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText='<%$Dict:clientAddWoFile.FieldReceivedColumnName %>'>
                  <ItemTemplate>
                    <asp:Label ID="Label111" runat="server" Text='<%# Container.DataItem  %>'></asp:Label>
                  </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText='<%$Dict:clientAddWoFile.mappedColumnName %>'>
                  <ItemTemplate>
                    <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# GetMappedTemplateColumn(Container.DataItemIndex) %>'>
                      <ItemTemplate>
                        <asp:Label runat="server" ID="fieldNameLbl" Text='<%# Eval("Lookup_CsvField.CsvField_Name") %>'>
                        </asp:Label>
                        <asp:HiddenField runat="server" ID="fieldNameHiden" Value='<%# Eval("Lookup_CsvField.Idx") %>' />
                        <br />
                      </ItemTemplate>
                    </asp:Repeater>
                  </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText='<%$Dict:ClientAddWoFile.IsKey.ColumnName %>'>
                  <ItemTemplate>
                    <asp:Repeater ID="Repeater1" runat="server" DataSource='<%# GetMappedTemplateColumn(Container.DataItemIndex) %>'>
                      <ItemTemplate>
                        <%--<asp:CheckBox runat="server" 
                                      ID="IsKeyCheckBox1" 
                                      Enabled="false"
                                      Checked='<%# Eval("IsKey") != null && (bool)Eval("IsKey") %>'>
                        </asp:CheckBox>--%>
                        <asp:Image ID="IsKeyImage" runat="server" ImageUrl="~/Images/Approve.gif"
                         Visible='<%# Eval("IsKey") != null && (bool)Eval("IsKey") %>' />
                        <asp:Image ID="IsNotKeyImage" runat="server" ImageUrl="~/Images/Icons/X.png"
                         Visible='<%# Eval("IsKey") == null || !(bool)Eval("IsKey") %>' />
                        <br />
                      </ItemTemplate>
                    </asp:Repeater>
                  </ItemTemplate>
                </asp:TemplateField>
               
              </Columns>
            </asp:GridView>
                
                <asp:GridView ID="userCsvNoHeaders" PageSize="20" AllowPaging="false" SkinID="GridViewSkin"
                  runat="server">
                  <Columns>
                  
                    <asp:TemplateField HeaderText='<%$Dict:clientAddWoFile.mappedColumnName %>'>
                      <ItemTemplate>
                        <asp:Label runat="server" ID="fieldNameLbl" Text='<%# Eval("Lookup_CsvField.CsvField_Name") %>'>
                        </asp:Label>
                        <asp:HiddenField runat="server" ID="fieldNameHiden" Value='<%# Eval("Lookup_CsvField.Idx") %>' />
                      </ItemTemplate>
                    </asp:TemplateField>
                    
                    
                    <asp:TemplateField HeaderText='<%$Dict:ClientAddWoFile.IsKey.ColumnName %>'>
                      <ItemTemplate>
                        <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# GetMappedTemplateColumn(Container.DataItemIndex) %>'>
                          <ItemTemplate>
                            <asp:CheckBox runat="server" 
                                          ID="IsKeyCheckBox2" 
                                          Enabled="false"
                                          Checked='<%# Eval("IsKey") != null && (bool)Eval("IsKey") %>'>
                            </asp:CheckBox>
                            <br />
                          </ItemTemplate>
                        </asp:Repeater>
                      </ItemTemplate>
                    </asp:TemplateField>
                    
                    
                  </Columns>
                </asp:GridView>
          </div>
          <div id="data_transfer_new_template" class="SC_FloatLeft SC_Align">
            <asp:Label ID="Label3" runat="server" Text='<%$Dict:clientAddWoFile.newTemplate %>'></asp:Label>
            <asp:Panel ID="NewTemplatePanel" runat="server">
   
                <table cellpadding="2" id="win-xp" cellspacing="2" border="0">
                  <tr>
                    <td>
                      <asp:DropDownList onchange="changeFieldNameToAdd(this)" runat="server"
                        ID="fieldIdxDdl">
                      </asp:DropDownList>
                    </td>
                    <td>
                      <asp:DropDownList ID="newFieldDdl" onchange="changeFieldNameToAdd(this)"
                        runat="server" DataSourceID="fieldNamesDs" DataTextField="CsvField_Name" DataValueField="Idx"
                        AppendDataBoundItems="true">
                        <asp:ListItem Selected="True" Text='<%$Dict:clientAddWoFile.ChooseFieldToAdd %>'>
                        </asp:ListItem>
                      </asp:DropDownList>
                    </td>
                    <td> 
                        <asp:CheckBox ID="IsKeyCheckBox" runat="server" Text='<%$Dict:ClientAddWoFile.IsKey.ColumnName %>' CssClass="regFont" />
                    </td>
                  </tr>
                </table>
                <br />
                <asp:Button runat="server" ID="clearFieldsBtn" CssClass="smallBtn Btn" Text='<%$Dict:clientAddWoFile.clearAllFiledS %>' />
                <asp:Button OnClick="addFieldBtnClicked" CssClass="smallBtn Btn" ID="Button1" runat="server"
                  Text='<%$Dict:clientAddWoFile.addFieldBtn %>' />
                <br /><br />
                <asp:GridView ID="fieldsToAddGrid" SkinID="GridViewSkin" runat="server" AllowPaging="false" >
                  <HeaderStyle CssClass="SC_grid_header"  />
                  <RowStyle CssClass="SC_grid_cell"  />
                  <Columns>
                    <asp:TemplateField HeaderText='<%$Dict:clientAddWoFile.orderHeader %>' SortExpression="MappedColName">
                      <ItemTemplate>
                        <%--<asp:Label ID="Label2" runat="server" Text='<%# Eval("MappedColName") %>'></asp:Label>--%>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("FileColumnName") %>'></asp:Label>
                      </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                      <HeaderTemplate>
                        <asp:Label ID="Label222" runat="server" Text='<%$Dict:clientAddWoFile.FieldName %>'></asp:Label>
                      </HeaderTemplate>
                      <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="fieldNamesDs" DataTextField="CsvField_Name"
                          DataValueField="Idx" SelectedValue='<%# Eval("Lookup_CsvField.Idx") %>'>
                        </asp:DropDownList>
                      </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                      <ItemTemplate>
                        <asp:ImageButton runat="server" CommandArgument='<%# Eval("Lookup_CsvField.Idx") %>'
                          OnClick="img_Click" ImageUrl='/Images/Cancel.gif' />
                      </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText='<%$Dict:ClientAddWoFile.IsKey.ColumnName %>'>
                        <ItemTemplate>
                            <asp:Image ID="IsKeyimage" runat="server" ImageUrl="~/Images/Approve.gif" Visible='<%# Eval("IsKey") %>' />
                            <asp:Image ID="IsNotKeyImage" runat="server" ImageUrl="~/Images/Cancel.gif" Visible='<%# !(bool)Eval("IsKey") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                  </Columns>
                </asp:GridView>
                <asp:LinqDataSource ID="fieldNamesDs" runat="server" ContextTypeName="MLY.Dal.lqKbmDataContext"
                  TableName="Lookup_CsvFields" >
                </asp:LinqDataSource>
                <asp:LinqDataSource ID="LinqDataSource1" EnableDelete="true" EnableUpdate="true"
                  EnableInsert="true" runat="server" ContextTypeName="MLY.Dal.lqKbmDataContext" TableName="TableCsvTemplateForUsers"
                  Where="templateId == @templateId" OrderBy="CsvTemplate_FieldOrder">
                  <WhereParameters>
                    <asp:ControlParameter ControlID="templateIdHidden" DefaultValue="-1" Name="templateId"
                      PropertyName="Value" Type="Int32" />
                  </WhereParameters>
                </asp:LinqDataSource>
                <br class="clr" />
                <br /><br />
                <asp:Button runat="server" ID="saveTemplateBtn" CssClass="smallBtn Btn" Text='<%$Dict:clientAddWoFile.csvFieldInTemplate %>' />
                <br class="clr" />
                <asp:Label runat="server" ForeColor="Red" ID="ErrLbl"></asp:Label>
                <asp:Panel runat="server" ID="templateSavePanel" CssClass="blueBorder" Visible="false">
                  <table cellpadding="5" cellspacing="0" border="0" style="width: 100%;">
                    <tr>
                      <td>
                        <asp:Label runat="server" Text='<%$Dict:clientAddWoFile.templateName %>'></asp:Label>
                      </td>
                      <td>
                        <asp:TextBox CssClass="blueBorder" runat="server" ID="templateNameTxt"></asp:TextBox>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="2">
                        <asp:Button CssClass="smallBtn Btn" OnClick="AddTemplateClicked" runat="server" Text='<%$Dict:clientAddWoFile.saveTemplate %>' />
                      </td>
                    </tr>
                  </table>
                </asp:Panel>
            </asp:Panel>
              
          </div>
        </asp:WizardStep>
        <asp:WizardStep runat="server" OnActivate="FinishStateActive" StepType="Finish">
            <div id="data_transfer_topRow_file_upload2">
                <img src="../Images/Icons/upload_img.png" alt="download" class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Upload data
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Choose a template
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Browse and check
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            <div class="SC_FloatLeft SC_data_transfer_toprowitem">
                Finish
            </div>
            <img src="../Images/Icons/data transfer_toprow_separator.png" alt="separator"  class="SC_FloatLeft" />
            </div>
            <div id="data_transfer_finish">
                <div id="data_transfer_finish_image" class="SC_FloatLeft"></div>
                <div id="data_transfer_finish_inside" class="SC_FloatLeft">
                    <asp:TextBox TextMode="MultiLine" ReadOnly="true" runat="server" CssClass="blueBorder"
                      BackColor="White" ID="logBox" Width="550" ForeColor="Black" Height="362"></asp:TextBox>
                </div>
            </div>
            
          
        </asp:WizardStep>
      </WizardSteps>

        <NavigationButtonStyle CssClass="Btn smallBtn"></NavigationButtonStyle>
    </asp:Wizard>
    
  </div>
  <asp:HiddenField runat="server" ID="Hidden1" />
</asp:Content>
